package 文件io;
import java.io.*;
import java.nio.charset.*;
/*
  转换流
  OutputStreamWriter  输入字符流转化为字节流
    数据流向 程序->OutputStreamWriter->OutputStream->文件
  InputStreamReader   输入字节流转化为字符流
    数据流向 文件->InputStream->InputStreamReader->程序
*/
public class 字节字符转换流
{
	public static void main(String[]args) throws FileNotFoundException {
		OutputStream out=new FileOutputStream(FilePath.PATH+"/test.txt",true);
		write(out);
		InputStream in=new FileInputStream(FilePath.PATH+"/test.txt");
		read(in);
		
	}
	//输入字节流转化为字符流
	private static void read(InputStream in){
		Reader reader=new InputStreamReader(in,Charset.defaultCharset());
		char[] cs=new char[1024];
		int len=-1;
		try
		{
			while ((len = reader.read(cs)) != -1)
			{
				System.out.println(new String(cs,0,len));
			}
		}
		catch (IOException e)
		{}
	}
	//输出字符流转化为字节流
	private static void write(OutputStream out){
		Writer writer=new OutputStreamWriter(out,Charset.defaultCharset());
		try
		{
			writer.write("哈哈哈我被添加了");
			writer.close();
		}
		catch (IOException e)
		{}
	}
}
